package easy;

public class Solution_661 {

    public int[][] imageSmoother(int[][] img) {
        int row = img.length;
        int col = img[0].length;
        int[][] ints = new int[row][col];
        for (int i = 0; i < row; i++) {
            for (int j = 0; j < col; j++) {
                int sum = img[i][j], count = 1;
                if (i - 1 >= 0) {
                    sum += img[i - 1][j];
                    count++;
                }
                if (i + 1 < row) {
                    sum += img[i + 1][j];
                    count++;
                }
                if (j - 1 >= 0) {
                    sum += img[i][j - 1];
                    count++;
                }
                if (j + 1 < col) {
                    sum += img[i][j + 1];
                    count++;
                }
                if (i - 1 >= 0 && j - 1 >= 0) {
                    sum += img[i - 1][j - 1];
                    count++;
                }
                if (i - 1 >= 0 && j + 1 < col) {
                    sum += img[i - 1][j + 1];
                    count++;
                }
                if (i + 1 < row && j - 1 >= 0) {
                    sum += img[i + 1][j - 1];
                    count++;
                }
                if (i + 1 < row && j + 1 < col) {
                    sum += img[i + 1][j + 1];
                    count++;
                }
                ints[i][j] = sum / count;
            }
        }
        return ints;
    }

    public static void main(String[] args) {
        Solution_661 model = new Solution_661();
        model.imageSmoother(new int[][]{});
        System.out.println();
    }
}
